package com.ruoyi.food.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.food.domain.OpmFoodSafeRisk;
import com.ruoyi.food.service.IOpmFoodSafeRiskService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 企业食品质量安全风险Controller
 *
 * @author cjie
 * @date 2021-07-24
 */
@Api(tags = " 企业食品质量安全风险")
@RestController
@RequestMapping("/opmFoodSafeRisk")
public class OpmFoodSafeRiskController extends BaseController {
    @Autowired
    private IOpmFoodSafeRiskService opmFoodSafeRiskService;

    /**
     * 查询企业食品质量安全风险列表
     */
    @ApiOperation(value="查询企业食品质量安全风险列表", notes="查询企业食品质量安全风险列表")
    @PreAuthorize(hasPermi = "food:opmFoodSafeRisk:list")
    @GetMapping("/list")
    public TableDataInfo list(OpmFoodSafeRisk opmFoodSafeRisk) {
        startPage();
        List<OpmFoodSafeRisk> list = opmFoodSafeRiskService.selectOpmFoodSafeRiskList(opmFoodSafeRisk);
        return getDataTable(list);
    }

    /**
     * 导出企业食品质量安全风险列表
     */
    @ApiOperation(value="导出企业食品质量安全风险列表", notes="导出企业食品质量安全风险列表")
    @PreAuthorize(hasPermi = "food:opmFoodSafeRisk:export")
    @Log(title = "企业食品质量安全风险", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OpmFoodSafeRisk opmFoodSafeRisk) throws IOException {
        List<OpmFoodSafeRisk> list = opmFoodSafeRiskService.selectOpmFoodSafeRiskList(opmFoodSafeRisk);
        ExcelUtil<OpmFoodSafeRisk> util = new ExcelUtil<OpmFoodSafeRisk>(OpmFoodSafeRisk.class);
        util.exportExcel(response, list, "企业食品质量安全风险数据");
    }
    /**
     * 获取企业食品质量安全风险详细信息
     */
    @ApiOperation(value="获取企业食品质量安全风险详细信息", notes="获取企业食品质量安全风险详细信息")
    @PreAuthorize(hasPermi = "food:opmFoodSafeRisk:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(opmFoodSafeRiskService.selectOpmFoodSafeRiskById(id));
    }

    /**
     * 新增企业食品质量安全风险
     */
    @ApiOperation(value="新增企业食品质量安全风险", notes="新增企业食品质量安全风险")
    @PreAuthorize(hasPermi = "food:opmFoodSafeRisk:add")
    @Log(title = "企业食品质量安全风险", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OpmFoodSafeRisk opmFoodSafeRisk) {
        return toAjax(opmFoodSafeRiskService.insertOpmFoodSafeRisk(opmFoodSafeRisk));
    }

    /**
     * 修改企业食品质量安全风险
     */
    @ApiOperation(value="修改企业食品质量安全风险", notes="修改企业食品质量安全风险")
    @PreAuthorize(hasPermi = "food:opmFoodSafeRisk:edit")
    @Log(title = "企业食品质量安全风险", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OpmFoodSafeRisk opmFoodSafeRisk) {
        return toAjax(opmFoodSafeRiskService.updateOpmFoodSafeRisk(opmFoodSafeRisk));
    }

    /**
     * 删除企业食品质量安全风险
     */
    @ApiOperation(value="删除企业食品质量安全风险", notes="删除企业食品质量安全风险")
    @ApiImplicitParam(name = "ids", value = "企业食品质量安全风险ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "food:opmFoodSafeRisk:remove")
    @Log(title = "企业食品质量安全风险", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(opmFoodSafeRiskService.deleteOpmFoodSafeRiskByIds(ids));
    }
}
